package com.captain.leetcode2.important;

import com.captain.leetcode.链表.ListNode;

public class 移除链表元素203 {

    public static void main(String[] args) {
        new com.captain.leetcode2.链表.移除链表元素203().removeElements(ListNode.getInstance(), 1);

    }

    public ListNode removeElements(ListNode head, int val) {
        if (head == null) return null;
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode cur = dummy;
        //输入：head = [-1 1,2,6,3,4,5,6], val = 6
        //输出：[1,2,3,4,5]
        while (cur.next != null) {
            int n = cur.next.val;
            if (n == val) {
                cur.next = cur.next.next;
            } else {
                //移动指针
                cur = cur.next;
            }

        }
        return dummy.next;
    }
}
